Guard.assertValidMetadataOrNull   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
const check = require('check-types');
2
3
/**
4
 * Various guards.
5
 */
6
class Guard {
7
8
    static assertNonEmptyStringParameter(name, value) {
9
        if (!check.nonEmptyString(value)) {
10
            throw new Error('Parameter "' + name + '" has to be an non-empty string.');
11
        }
12
    }
13
14
    static assertValidMetadata(metadata) {
15
        if (!check.nonEmptyObject(metadata)) {
16
            throw new Error('Metadata on an node has to be an object.');
17
        }
18
    }
19
20
    static assertValidMetadataOrNull(metadataOrNull) {
21
        if (check.assigned(metadataOrNull)) {
22
            Guard.assertValidMetadata(metadataOrNull);
23
        }
24
    }
25
26
    static assertValidDirected(directed) {
27
        if (!check.boolean(directed)) {
28
            throw new Error('Directed flag on an edge has to be boolean.');
29
        }
30
    }
31
}
32
33
module.exports = {
34
    Guard,
35
};